<?php

namespace Home\Controller;

use Think\Controller;

/**
 * 管理商店和渠道
 *
 * 和数据库关联， 管理 网上店面来源
 *
 * 平台来源， 百度，美团，饿了么， 其他合作渠道
 * 店面，自有平台（有赞，点单宝）， 百度三家店面（ 小飞侠，新街口，朝阳门），美团1家，饿了么2家
 *
 * 店面名称，dmid编号，所属平台，
 *
 * @author jdong
 *        
 */
class ShopController extends Controller {
	public function index() {
		// $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
	
	   //  $this->plat();
// 	     $this->display ("/shop/plat");
		$this->display ();
	}
	public function plat() {
		// require_once C ( 'CUSTOM_LIBRARY' ) . '/httpful-2.phar';
		$plat = M ( "wmplatform" );
		
		if (IS_POST) {
			
			$data = $plat->create ();
			$data ["date"] = date ( 'Y-m-d H:i:s' );
			$data ["del"] = 0;
			
			try {
				$plat->data ( $data )->add ();
			} catch ( \Think\Exception $e ) {
				
				$this->error ( '新增失败！'.$e->getMessage () );
				return;
			}
			
			$this->success ( '新增成功！', '../shop/plat', 1 );
			return;
		}
		
		$op = I ( "op" );
		$key = I ( "id" );
		if ($op == "del") {
			$map ['id'] = $key;
			$data ['del'] = 1;
			$plat->where ( $map )->save ( $data );
			unset ( $map );
		} 
		
		
		$map ['del'] = 0;
		$list = $plat->where ( $map )->field ( 'id,name,ptid,manager,mobile,memo,date' )->select ();
		
		$this->assign ( 'list', $list );
		
		$this->display ();
	}
	
	public function update() {
		// require_once C ( 'CUSTOM_LIBRARY' ) . '/httpful-2.phar';
		$plat = M ( "wmplatform" );
	
		if (IS_POST) {
				
			$data = $plat->create ();
			$data ["date"] = date ( 'Y-m-d H:i:s' );
			$data ["del"] = 0;
				
			try {
				$plat->save($data);
			} catch ( \Think\Exception $e ) {
	
				$this->error ( '更新失败！'.$e->getMessage ());
				return;
			}
				
			$this->success ( '更新成功！', '../shop/plat', 1 );
			return;
		}
	 
	
		$map ['del'] = 0;
		$map ['id'] = I ( "id" );
		$list = $plat->where ( $map )->field ( 'id,name,ptid,manager,mobile,memo,date' )->select ();
	
		$this->assign ( 'list', $list );
	
		$this->display ();
	}
	
	public function dm() {
		// require_once C ( 'CUSTOM_LIBRARY' ) . '/httpful-2.phar';
		$plat = M ( "wmdm" );
	
		if (IS_POST) {
	
			$data = $plat->create ();
			$data ["date"] = date ( 'Y-m-d H:i:s' );
			
// 			var_dump($data);
			 
	
			try {
				$plat->add($data);
			} catch ( \Think\Exception $e ) {
	
				$this->error ( '新增失败！' .$e->getMessage () );
				return;
			}
	
			$this->success ( '新增成功！', '../shop/dm', 1 );
			return;
		}
	
		
		$op = I ( "op" );
		$key = I ( "id" );
		if ($op == "del") {
			$map ['id'] = $key;
			$data ['del'] = 1;
			$plat->where ( $map )->save ( $data );
			unset ( $map );
		}
	
		
	
		$map ['del'] = 0;
		$list = $plat->where($map)->field ( 'id,dmid,dmname,ptid,manager,mobile,address,url,user,password,cookie,memo,date' )->select ();
		
		$wmplat = M ( "wmplatform" );
		$ptlist = $wmplat->field ( 'ptid,name' )->select ();
	
		$this->assign ( 'list', $list );
		$this->assign ( 'ptlist', $ptlist );
	
		$this->display ();
	}
	
	public function dmupdate() {
		// require_once C ( 'CUSTOM_LIBRARY' ) . '/httpful-2.phar';
		$plat = M ( "wmdm" );
	
		if (IS_POST) {
	
			$data = $plat->create ();
			$data ["date"] = date ( 'Y-m-d H:i:s' );
			$data ["del"] = 0;
	
			try {
				$plat->save($data);
			} catch ( \Think\Exception $e ) {
	
				$this->error ( '更新失败！'.$e->getMessage ()  );
				return;
			}
	
			$this->success ( '更新成功！', '../shop/dm', 1 );
			return;
		}
	
	
	 
		$map ['id'] = I ( "id" );
		$map ['del'] = 0;
		$list = $plat->where($map)->field ( 'id,dmid,dmname,ptid,manager,mobile,address,url,user,password,cookie,memo,date' )->select ();
		
		$wmplat = M ( "wmplatform" );
		$ptlist = $wmplat->field ( 'ptid,name' )->select ();
	
		$this->assign ( 'list', $list );
		$this->assign ( 'ptlist', $ptlist );
	
		$this->display ();
	}
	
}